<?php if(!defined('IN_FIRADIO')) {header('HTTP/1.1 403 Forbidden');exit('<h1>Access Denied</h1>');}?>
<?php $GLOBALS['script'][] = function() {?><script>
vue.data.api = {};
vue.data.apidata = {};
vue.data.disabled = 0;
vue.data.flag = {};
vue.data.flag.main = 'list';
vue.data.flag.info = 'info';
vue.data.form = {};
vue.data.form.qquin = null;
vue.data.form.password = null;
vue.data.choice_hostuser = {};
vue.data.display_field = {};
vue.data.display_field.hvu = {"visible":false, "title":"HVU"};
vue.data.display_field.username = {"visible":false, "title":"计费账户"};
vue.data.display_field.wanipv4 = {"visible":false, "title":"公网IP"};
vue.data.display_field.host_type = {"visible":false, "title":"类型"};
vue.data.display_field.host_area = {"visible":false, "title":"地域"};
vue.data.display_field.host_name = {"visible":false, "title":"机号"};
vue.data.display_field.host_title = {"visible":false, "title":"主机特点"};
vue.data.display_field.host_osname = {"visible":false, "title":"操作系统"};
vue.data.display_field.remaindays = {"visible":false, "title":"剩余天数"};
vue.data.display_field.state = {"visible":true, "title":"状态"};

vue.methods.toTop = function() {
    top.document.documentElement.scrollTop = 0;
    top.document.getElementById('iframe_content').height = 0;
    //alert('请刷新');
};
vue.methods.submit_list = function () {
    const form = {};
    this.ApiPost('/panel/yun/nthost/userlist.php', form).then(function (res) {
        vue.data.apidata = res.data;
        for (var key in vue.data.apidata.rows_user) {
            const row = vue.data.apidata.rows_user[key];
            row['userjson'] = vue.methods.getnew_userdata(row['userjson']);
        }

        /*
        setTimeout(function () {
            jQuery('.dataTable').DataTable({
                'paging'      : false,
                'lengthChange': false,
                'searching'   : false,
                'ordering'    : true,
                'info'        : false,
                'autoWidth'   : true
            })
        }, 1);//*/
    }, function (res) {
        console.log('reject:', res);
    }).catch(function (reason) {
        console.log('catch:', reason);
    })
};
vue.methods.submit_refund = function () {
    const form = window.clone(vue.data.form);
    this.ApiPost('/panel/yun/nthost/refund.php', form).then(function (res) {
        //vue.data.apidata = res.data;
    }, function (res) {
        console.log('reject:', res);
    }).catch(function (reason) {
        console.log('catch:', reason);
    })
};
vue.methods.submit_operate = function () {
    vue.data.disabled++;
    const form = window.clone(vue.data.form);
    form.host_id = vue.data.choice_hostuser.host_id;
    form.username = vue.data.choice_hostuser.username;
    this.ApiPost('/panel/yun/nthost/operate.php', form).then(function (res) {
        //vue.data.apidata = res.data;
    }, function (res) {
        console.log('reject:', res);
    }).catch(function (reason) {
        console.log('catch:', reason);
    }).then(function () {
        vue.data.disabled--;
    });
};
vue.methods.submit_ticket = function () {
    const form = window.clone(vue.data.form);
    form.host_id = vue.data.choice_hostuser.host_id;
    form.username = vue.data.choice_hostuser.username;
    this.ApiPost('/panel/yun/nthost/ticket_thread_add.php', form).then(function (res) {
        //vue.data.apidata = res.data;
    }, function (res) {
        console.log('reject:', res);
    }).catch(function (reason) {
        console.log('catch:', reason);
    })
};
vue.methods.destroy = function () {
    var msg = "销毁主机将导致储存到该主机上的所有数据丢失！！！\r\n";
    msg += "↓↓↓您要销毁的主机信息↓↓↓\r\n";
    if (vue.data.choice_hostuser.vps_wanipv4) {
        msg += "主机远程登录地址：" + vue.data.choice_hostuser.vps_wanipv4 + "\r\n";
    } else {
        msg += "主机远程登录地址：" + vue.data.choice_hostuser.rdpaddr + ":" + vue.data.choice_hostuser.rdpport + "\r\n";
        msg += "主机远程登录用户名：" + vue.data.choice_hostuser.username + "\r\n";
    }
    msg += "确定要销毁该主机上包括D盘在内的所有数据吗？\r\n";
    msg += "（成功销毁的主机将停止计费，直到你重新开通主机。）";
    if (confirm(msg)) {
        vue.data.form.action = 'destroy';
        vue.methods.submit_operate();
    }
};
vue.methods.logoff = function () {
    var msg = "";
    msg += "注销会话只是帮你退出所有运行中的软件，并不会删除任何数据\r\n";
    msg += "↓↓↓您要注销会话的主机信息↓↓↓\r\n";
    msg += "主机远程登录地址：" + vue.data.choice_hostuser.rdpaddr + ":" + vue.data.choice_hostuser.rdpport + "\r\n";
    msg += "主机远程登录用户名：" + vue.data.choice_hostuser.username + "\r\n";
    msg += "确定要注销会话吗？";
    if (confirm(msg)) {
        vue.data.form.action = 'logoff';
        vue.methods.submit_operate();
    }
};
vue.methods.reboot = function () {
    var msg = "";
    msg += "强制重启系统并不会删除任何数据\r\n";
    msg += "↓↓↓您要强制重启的主机信息↓↓↓\r\n";
    msg += "主机远程登录地址：" + vue.data.choice_hostuser.vps_wanipv4 + "\r\n";
    msg += "确定要强制重启系统吗？";
    if (confirm(msg)) {
        vue.data.form.action = 'reboot';
        vue.methods.submit_operate();
    }
};
vue.methods.refund = function () {
    var msg = "";
    msg += "退回押金后将自动删除该订单，可能无法再次购买相同产品！\r\n";
    msg += "↓↓↓这是您要删除的订单↓↓↓\r\n";
    if (vue.data.choice_hostuser.vps_wanipv4) {
        msg += "主机远程登录地址：" + vue.data.choice_hostuser.vps_wanipv4 + "\r\n";
    } else {
        msg += "主机远程登录地址：" + vue.data.choice_hostuser.rdpaddr + ":" + vue.data.choice_hostuser.rdpport + "\r\n";
        msg += "主机远程登录用户名：" + vue.data.choice_hostuser.username + "\r\n";
    }
    msg += "原路退回押金 " + vue.data.choice_hostuser.holdbalance + " 点数\r\n";
    msg += "确定要退回押金并删除订单吗？";
    if (confirm(msg)) {
        vue.methods.submit_refund();
    }
};
vue.methods.start_rdp = function () {
    if(!/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
        alert('请在手机里使用这个功能');
    }
    if(/iPhone/i.test(navigator.userAgent)) {
        alert('苹果手机请手动添加');
    }
    const choice_hostuser = vue.data.choice_hostuser;
    const rdp_config_arr = {};
    rdp_config_arr['full address'] = vue.data.choice_hostuser.rdpaddr + ":" + vue.data.choice_hostuser.rdpport;
    //rdp_config_arr['audiomode'] = 0;
    //rdp_config_arr['disable themes'] = 0;
    rdp_config_arr['domain'] = 'FIRADIO';
    rdp_config_arr['username'] = choice_hostuser.username;
    rdp_config_arr['drivestoredirect'] = '*';
    rdp_config_arr['authentication level'] = 0; // 0: Connect and don’t warn me
    //rdp_config_arr['desktopwidth'] = 1366;
    //rdp_config_arr['desktopheight'] = 768;
    const out = [];
    for (var key in rdp_config_arr) {
        const v = rdp_config_arr[key];
        var type = 'i';
        if (typeof(v) === 'string') type = 's';
        if (typeof(v) === 'number') type = 'i';
        out.push(encodeURIComponent(key) + '=' + type + ':' + encodeURIComponent(v));
    }
    //alert(out.join('&'));
    const rdp = 'rdp://' + out.join('&');
    location.href = rdp;
};
vue.methods.tabclick = function (name) {
    jQuery("li a[href='#tab-" + name + "']").click();
    vue.methods.toTop();
};
vue.methods.click_info = function (row) {
    vue.data.flag.main = 'info';
    vue.data.choice_hostuser = row;
    vue.data.form.nthost_user_id = row['id'];
    vue.data.form.pack_id = row['pack_id'];
    vue.data.form.userjson = row['userjson'];
};
vue.methods.getnew_userdata = function (_userjson) {
    var userjson = JSON.parse(_userjson);
    if (userjson === null) userjson = {};
    const fields = window.clone(vue.data.userdata_fields);
    for (var name in fields) {
        const attr = fields[name];
        if (userjson.hasOwnProperty(name)) {
            if (typeof(userjson[name]) === 'object') {
                attr.value = userjson[name].value;
            }
        }
    }
    return fields;
};
vue.mounted = function () {
    const that = this;
    vue.methods.submit_list();
    window.onresize = () => {
        this.$nextTick(() => {
            vue.data.display_field.hvu.visible = false;
            vue.data.display_field.username.visible = true;
            vue.data.display_field.wanipv4.visible = false;
            vue.data.display_field.host_type.visible = true;
            vue.data.display_field.host_area.visible = false;
            vue.data.display_field.host_name.visible = false;
            vue.data.display_field.host_title.visible = false;
            vue.data.display_field.host_osname.visible = false;
            vue.data.display_field.remaindays.visible = false;
            if (document.body.clientWidth > 400) {
                vue.data.display_field.remaindays.visible = true;
                vue.data.display_field.wanipv4.visible = true;
                vue.data.display_field.host_osname.visible = true;
            }
            if (document.body.clientWidth > 800) {
                vue.data.display_field.hvu.visible = true;
                vue.data.display_field.host_area.visible = true;
                vue.data.display_field.host_name.visible = true;
                vue.data.display_field.host_title.visible = true;
            }
        });

    }
};
</script><?php }?>


<div class="row">
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" v-if="flag.main=='list'">
        <div class="box box-default" v-if="apidata.rows_user">
            <div style="padding-left: 20px;">
                系统列：
                <label v-for="(val,name) in display_field">
                    <input v-model="val.visible" type="checkbox" />{{val.title}}&nbsp;
                </label>
                <br />
                用户列：
                <label v-for="(attr,name) in userdata_fields">
                    <input v-model="attr.visible" type="checkbox" />{{attr.title}}&nbsp;
                </label>
            </div>
            <table
            v-if="apidata.rows_user.length>0"
            id="example1" class="table table-bordered table-hover table-striped dataTable" role="grid" aria-describedby="example1_info">
                <thead>
                    <tr role="row">
                        <th v-for="(val,name) in display_field" v-if="val.visible">{{val.title}}</th>
                        <td v-for="(attr,name) in userdata_fields" v-if="attr.visible">{{attr.title}}</td>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <tr role="row" class="odd" v-for="row in apidata.rows_user">
                      <td v-if="display_field.hvu.visible">{{row['id']}}</td>
                      <td v-if="display_field.username.visible">{{row['username']}}</td>
                      <td v-if="display_field.wanipv4.visible">
                        <span v-if="row['vps_wanipv4']">{{row['vps_wanipv4']}}</span>
                        <span v-else>{{row['wanipv4']}}</span>
                      </td>
                      <td v-if="display_field.host_type.visible">
                        <span v-if="row['host_type']==1" style="color:green">共享Win</span>
                        <span v-else-if="row['host_type']==2" style="color:blue">独立VPS</span>
                        <span v-else>-</span>
                      </td>
                      <td v-if="display_field.host_area.visible">{{row['host_area']}}</td>
                      <td v-if="display_field.host_name.visible">{{row['host_name']}}</td>
                      <td v-if="display_field.host_title.visible">{{row['host_title']}}</td>
                      <td v-if="display_field.host_osname.visible">
                        <span v-if="row['vps_osname']">{{row['vps_osname']}}</span>
                        <span v-else>{{row['host_osname']}}</span>
                      </td>
                      <td v-if="display_field.remaindays.visible">
                        <span v-if="row['host_type']==1" style="color:green">永久</span>
                        <span v-else-if="row['host_type']==2">
                            <span style="color:red" v-if="value_remaindays(row)<3">{{formatDays(value_remaindays(row))}}</span>
                            <span style="color:blue" v-else>{{formatDays(value_remaindays(row))}}</span>
                        </span>
                        <span v-else>-</span>
                      </td>
                      <td v-if="display_field.state.visible">
                        <span v-if="row['operated']" style="color: red;">处理中</span>
                        <span v-else-if="row['destroyed']" style="color: #999999;">已销毁</span>
                        <span v-else-if="row['opened']" style="color: green;">已开通</span>
                        <span v-else-if="row['stopped']" style="color: #990000;">已停机</span>
                        <span v-else style="color: blue;">请开通</span>
                      </td>
                      <td v-for="(attr,name) in userdata_fields" v-if="attr.visible">
                        <span v-if="row['userjson'][name]&&row['userjson'][name].value">
                          {{row['userjson'][name].value}}
                        </span>
                        <span v-else>-</span>
                      </td>
                      <td><button class="btn btn-primary btn-xs" type="button" v-on:click="click_info(row)">详情</button></td>
                    </tr>
                </tbody>
            </table>
            <div v-else>
                <h2>您尚未申请过任何主机，请先申请。</h2>
            </div>
        </div>
        <div v-else>
            <h2>数据载入中，请稍候...</h2>
        </div>
    </div>
    <div class="col-xs-12 col-sm-8 col-md-6 col-lg-6" v-if="flag.main=='info'">
        <div class="box box-default">
            <div class="box-header with-border">
                <i class="fa fa-laptop"></i>
                <h3 class="box-title">我的远程主机 (HVU:{{choice_hostuser['id']}})</h3>
                <div class="pull-right">
                    <button class="btn btn-info btn-xs" type="button" v-on:click="flag.info='ticket';toTop()" v-if="0">发起工单</button>
                    <button class="btn btn-primary btn-xs" type="button" v-on:click="flag.main='list';toTop()">返回列表</button>
                </div>
            </div>
            <div class="nav-tabs-custom">
                <ul class="nav nav-tabs">
                    <li class="active"><a href="#tab-info" data-toggle="tab">详情</a></li>
                    <li><a href="#tab-userjson" data-toggle="tab">用户备注</a></li>
                    <li v-if="choice_hostuser['host_type']==2"><a href="#tab-repack" data-toggle="tab">变更配置</a></li>
                    <li v-if="!choice_hostuser.opened"><a href="#tab-open" data-toggle="tab">开通主机</a></li>
                    <li v-if="choice_hostuser['host_type']==2&&choice_hostuser.opened"><a href="#tab-rebuild" data-toggle="tab">重装系统</a></li>
                    <li v-if="choice_hostuser.opened"><a href="#tab-admin" data-toggle="tab">管理主机</a></li>
                    <li v-if="choice_hostuser.opened"><a href="#tab-setpwd" data-toggle="tab">重设密码</a></li>
                    <li v-if="choice_hostuser.opened||choice_hostuser.stopped"><a href="#tab-destroy" data-toggle="tab">销毁主机</a></li>
                </ul>
                <div class="tab-content">
<?php
$root = substr(__FILE__, 0, strrpos(__FILE__, '.'));
$dirs = scandir($root);
foreach ($dirs as $file) {
    $path = $root . '/' . $file;
    if (!is_file($path)) continue;
    $fileName = substr($file, 0, strrpos($file, '.'));
    $active = ($fileName === 'info') ? ' active' : '';
?>
                    <div class="tab-pane<?php echo $active;?>" id="tab-<?php echo $fileName;?>"><?php include $path;?></div>
<?php
}
?>
                </div>
            </div>
        </div>
    </div>
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        <div class="box box-info">
            <div class="box-header with-border">
                <i class="fa fa-info-circle"></i>
                <h3 class="box-title">温馨提醒</h3>
            </div>
            <div class="box-body">
                <ol>
                    <li>
                        Windows远程桌面管理软件下载
                        <ul>
                            <li>
                                苹果 App Store 安装：<a target="_blank" href="https://apps.apple.com/cn/app/microsoft-%E8%BF%9C%E7%A8%8B%E6%A1%8C%E9%9D%A2/id714464092">微软官方中文版</a>（需要iOS13系统）
                            </li>
                            <li>
                                安卓 Google Play 安装：<a target="_blank" href="https://play.google.com/store/apps/details?id=com.microsoft.rdc.android&hl=zh">官方英文版</a>（中国大陆用户需翻墙）
                            </li>
                            <li>
                                安卓 APK 下载：<a target="_blank" href="http://cdn.firadio.net/down/pack/com.microsoft.rdc.android-8.1.79.421.apk">8.1.79.421</a>（无需翻墙）
                            </li>
                            <li>
                                Win7/Win10电脑请通过[Win]+[R]呼出[运行]mstsc即可
                            </li>
                        </ul>
                    </li>
                    <li>
                        <span style="color:green">共享型</span>VPS常见问题
                        <ul>
                            <li>
                                Win2019主机登录后会黑屏1-2分钟属于正常情况，建议换用Win2012R2系统。
                            </li>
                        </ul>
                    </li>
                    <li>
                        <span style="color:blue">独立型</span>VPS常见问题
                        <ul>
                            <li>
                                独立VPS开通主机后需要等待1-3分钟，后台安装系统需要些时间。
                            </li>
                            <li>
                                Windows独立VPS没有声音，需要在右下角自行开启声音服务。
                            </li>
                            <li>
                                Windows独立VPS无法下载，需要修改IE浏览器安全设置。
                            </li>
                        </ul>
                    </li>
                    <li>
                        关于押金与欠费的说明
                        <ul>
                            <li>
                                押金只在新购或升级配置时收取，
                                并在关闭订单时退回（需先付清欠费账单）。
                            </li>
                            <li>
                                账单只能通过余额消费，押金不会扣。
                                余额不足时将产生欠款，欠款超过押金时会自动停机。
                            </li>
                            <li>
                                停机后需要付清欠款账单才能开机，押金不能抵扣。
                            </li>
                        </ul>
                    </li>
                    <li>
                        为了方便大家试用主机，
                        我们飞儿云主机均按量计费（精确到1秒），
                        可随时退费，从而避免造成资源浪费。
                        <ul>
                            <li>
                                <span style="color:green">共享机</span>按照
                                <a style="color:red" href="javascript:void(0)"
                                onclick="alert('当CPU单核率占用100%时，每1秒计费1点数\r\n当CPU单核率占用50%时，每2秒计费1点数\r\n当CPU单核率占用20%时，每5秒计费1点数')">
                                实际CPU使用率</a> 来计费（注销会话就会停止计费），<br />
                            </li>
                            <li>
                                <span style="color:blue">独立VPS</span>按照运行时间计费（注销后仍会计费）
                            </li>
                            <li>
                                有任何不满意的请及时销毁主机后退回押金。
                            </li>
                        </ul>
                    </li>
                </ol>
            </div>
        </div>
    </div>

</div>
